﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Store;

namespace AMM.UserControls {
    public partial class VendorSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int currencyValue = Convert.ToInt32(this.cmbCurrency.SelectedValue);
            int statusValue = Convert.ToInt32(this.cmbStatus.SelectedValue);
            int typeValue = Convert.ToInt32(this.cmbType.SelectedValue);
            int enabledValue = Convert.ToInt32(this.cmbIsEnabled.SelectedValue);

            VendorSearchModel searchResult = new VendorSearchModel();
            searchResult.Code = this.tbCode.Text;
            searchResult.Name = this.tbName.Text;
            searchResult.Address = this.tbAddress.Text;
            searchResult.PayCurrencyId = currencyValue;
            searchResult.VendorStatusId = statusValue;
            searchResult.VendorTypeId = typeValue;
            searchResult.IsEnabled = Convert.ToBoolean(enabledValue);

            if (currencyValue == 0) { searchResult.PayCurrencyId = null; }
            if (statusValue == 0) { searchResult.VendorStatusId = null; }
            if (typeValue == 0) { searchResult.VendorTypeId = null; }
            if (enabledValue == -1) { searchResult.IsEnabled = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbCode.Clear();
            this.tbName.Clear();
            this.tbAddress.Clear();
            this.cmbCurrency.SelectedIndex = 0;
            this.cmbStatus.SelectedIndex = 0;
            this.cmbType.SelectedIndex = 0;
            this.cmbIsEnabled.SelectedValue = "-1";
        }

        public VendorSearchControl() {
            this.InitializeComponent();           
        }

        private void VendorSearchControl_Load(object sender, EventArgs e) {
            this.BindBasics(this.cmbCurrency, BasicsType.Currency);
            this.BindBasics(this.cmbStatus, BasicsType.VendorStatus);
            this.BindBasics(this.cmbType, BasicsType.VendorType);
            this.BindIsEnabled(this.cmbIsEnabled);
        }
    }
}
